import { ProFormSelect } from '@ant-design/pro-components';
import { type ProFormSelectProps } from '@ant-design/pro-form/lib/components/Select';

const CommonFormSelect: React.FC<ProFormSelectProps> = ({ required, rules = [], ...props }) => {
  const requiredMsgText = props.mode === 'tags' ? '请输入' : '请选择';
  return (
    <ProFormSelect
      {...props}
      rules={
        rules.some((rule) => 'required' in rule)
          ? rules
          : [
              {
                required,
                message: `${requiredMsgText}${props.label}`,
              },
              ...rules,
            ]
      }
    />
  );
};

CommonFormSelect.defaultProps = { required: false, mode: 'single' };

export default CommonFormSelect;
